﻿namespace il2lua.Services;

public static class Services
{
    private static Dictionary<Type, Lazy<IService>> _services = new Dictionary<Type, Lazy<IService>>();
    static Services()
    {
        _services[typeof(INameService)] = new Lazy<IService>(() => new NameService());
    }
    public static T GetService<T>() where T : IService
    {
        _services.TryGetValue(typeof(T), out var service);
        if (service != null && service.Value is T s)
            return s;
        throw new InvalidOperationException("没有该服务！" + typeof(T).FullName);
    }
}